Skip to content

feat(widget): expose solana transactions as hex for external providers#545

Merged
petar-omni merged 1 commit into
mainfrom
feat/expose-solana-tx-as-hex
Jun 24, 2026
Merged

feat(widget): expose solana transactions as hex for external providers#545
petar-omni merged 1 commit into
mainfrom
feat/expose-solana-tx-as-hex

Conversation

@petar-omni

@petar-omni petar-omni commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Move Solana transaction decoding into shared domain helpers and convert base64 payloads to hex before forwarding them to external wallet providers. Hex-encoded transactions are preserved in hex form so providers receive a consistent encoding.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Solana transaction handling for external wallet flows, helping transactions decode more consistently across hex and base64 formats.
    • Better error reporting when Solana transaction decoding fails, making failures easier to diagnose.
    • Normalizes Solana transaction data before signing, reducing format-related issues.
  • Tests

    • Updated Solana transaction coverage to reflect the new decoding and normalization behavior.

@changeset-bot

changeset-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 9b1b0eb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds decodeSolanaTransactionToBuffer and normalizeSolanaTransactionToHex helpers to the transaction domain. The solana-connector deserialization is refactored from a multi-candidate loop to a single decode call. The external provider signing path in SKWalletProvider now normalizes Solana transactions to hex. Tests are updated accordingly.

Changes

Solana Transaction Normalization

Layer / File(s) Summary
Encoding types and buffer/hex conversion utilities
packages/widget/src/domain/types/transaction.ts
Adds internal SolanaTransactionEncoding and SolanaTransactionBytes type aliases, hex-detection logic (strips optional 0x, validates even length and hex regex), and exports decodeSolanaTransactionToBuffer (returns { encoding, buffer }) and normalizeSolanaTransactionToHex (converts decoded bytes to a hex string).
solana-connector deserialization refactor
packages/widget/src/providers/misc/solana-connector.ts
Removes getSolanaTxDecodingCandidates and the multi-candidate iteration; replaces with a single decodeSolanaTransactionToBuffer call followed by VersionedTransaction.deserializeTransaction.from fallback. Error message now includes encoding, bufferLength, and both caught error messages.
External provider signing normalization
packages/widget/src/providers/sk-wallet/index.tsx
Imports normalizeSolanaTransactionToHex and applies it to the decoded Solana transaction v before setting tx in the { type: "solana", tx } external provider payload.
Test suite updates
packages/widget/tests/use-cases/solana-connector.test.ts, packages/widget/tests/use-cases/sk-wallet.test.tsx
Rewrites connector decoding tests to call decodeSolanaTransactionToBuffer directly and assert encoding/buffer; introduces createSolanaTxMeta() helper in sk-wallet tests and applies it to signTransaction inputs and sendTransactionSpy expectations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • stakekit/widget#518: Introduced the original getSolanaTxDecodingCandidates candidate-based deserialization logic in solana-connector.ts that this PR directly replaces with the decodeSolanaTransactionToBuffer flow.

Suggested reviewers

  • Philippoes

Poem

🐇 Hop hop, no more candidate loops in sight,
A single decode step, clean and right!
Hex or base64, the buffer knows,
Normalized to hex — off it goes.
The widget signs with confidence now,
CodeRabbit approves with a happy bow! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description lacks the required Added and Changed sections from the template and doesn't separate new vs modified behavior. Add the ## Added and ## Changed headings and summarize the new helper logic plus the Solana provider behavior changes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: Solana transactions are normalized to hex for external providers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/expose-solana-tx-as-hex

Comment @coderabbitai help to get the list of available commands.

@petar-omni petar-omni force-pushed the feat/expose-solana-tx-as-hex branch from a8a83fd to 429faec Compare June 24, 2026 09:47
Move Solana transaction decoding into shared domain helpers and convert
base64 payloads to hex before forwarding them to external wallet providers.
Hex-encoded transactions are preserved in hex form so providers receive a
consistent encoding.
@petar-omni petar-omni force-pushed the feat/expose-solana-tx-as-hex branch from 429faec to 9b1b0eb Compare June 24, 2026 09:47
@aws-amplify-eu-central-1

Copy link
Copy Markdown

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-545.df4xyoi0xyeak.amplifyapp.com

@aws-amplify-eu-central-1

Copy link
Copy Markdown

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-545.d2ribjy8evqo6h.amplifyapp.com

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/widget/src/domain/types/transaction.ts`:
- Around line 136-162: The transaction decoding logic in
decodeSolanaTransactionToBuffer and isSolanaHexTransaction is too permissive
because any even-length hex-looking string is auto-treated as hex, which can
misdecode valid base64 payloads. Tighten the detection contract so hex is only
chosen with an explicit prefix like 0x, or add a safe fallback path that tries
base64 when hex is ambiguous or cannot be deserialized. Keep the change
localized to the helpers in transaction.ts and preserve the returned
SolanaTransactionBytes encoding/buffer shape.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ba7e272-6bf3-4bac-98f5-c8af22a1743c

📥 Commits

Reviewing files that changed from the base of the PR and between 660ad89 and 9b1b0eb.

📒 Files selected for processing (5)
  • packages/widget/src/domain/types/transaction.ts
  • packages/widget/src/providers/misc/solana-connector.ts
  • packages/widget/src/providers/sk-wallet/index.tsx
  • packages/widget/tests/use-cases/sk-wallet.test.tsx
  • packages/widget/tests/use-cases/solana-connector.test.ts

Comment on lines +136 to +162
const isSolanaHexTransaction = (tx: DecodedSolanaTransaction): boolean => {
const withoutHexPrefix = stripSolanaHexPrefix(tx.trim());

return (
withoutHexPrefix.length > 0 &&
withoutHexPrefix.length % 2 === 0 &&
solanaHexStringRegex.test(withoutHexPrefix)
);
};

export const decodeSolanaTransactionToBuffer = (
tx: DecodedSolanaTransaction
): SolanaTransactionBytes => {
const normalizedTx = tx.trim();
const withoutHexPrefix = stripSolanaHexPrefix(normalizedTx);

if (isSolanaHexTransaction(normalizedTx)) {
return {
encoding: "hex",
buffer: Buffer.from(withoutHexPrefix, "hex"),
};
}

return {
encoding: "base64",
buffer: Buffer.from(normalizedTx, "base64"),
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Resolve ambiguous unprefixed base64-vs-hex payloads.

Line 152 makes any even-length hex-only string decode as hex, but those strings can also be valid base64 text. That changes the decoded bytes before both Solana deserialization and external-provider normalization. Prefer an explicit contract, e.g. require 0x for hex auto-detection, or reintroduce a base64 fallback when hex decoding cannot deserialize.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/widget/src/domain/types/transaction.ts` around lines 136 - 162, The
transaction decoding logic in decodeSolanaTransactionToBuffer and
isSolanaHexTransaction is too permissive because any even-length hex-looking
string is auto-treated as hex, which can misdecode valid base64 payloads.
Tighten the detection contract so hex is only chosen with an explicit prefix
like 0x, or add a safe fallback path that tries base64 when hex is ambiguous or
cannot be deserialized. Keep the change localized to the helpers in
transaction.ts and preserve the returned SolanaTransactionBytes encoding/buffer
shape.

@jdomingos jdomingos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@dnehl dnehl left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing spotted - looks good

@petar-omni petar-omni merged commit 2de9c9f into main Jun 24, 2026
7 checks passed
@petar-omni petar-omni deleted the feat/expose-solana-tx-as-hex branch June 24, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants